<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
  // window.onhashchange = function(){}
  window.addEventListener('hashchange', (ev) => {
    console.log('ev:',ev);
  });

  //打开控制台
/*
location = '#abc'
"#abc"
02pushState不会触发hashchange事件.html?_ijt=pkstdjn82gunkjujrusdgvfh41:11 ev: HashChangeEvent {isTrusted: true, oldURL: "http://localhost:63342/javascript_core/BOM%E5%92%8…%8B%E4%BB%B6.html?_ijt=pkstdjn82gunkjujrusdgvfh41", newURL: "http://localhost:63342/javascript_core/BOM%E5%92%8…E4%BB%B6.html?_ijt=pkstdjn82gunkjujrusdgvfh41#abc", type: "hashchange", target: Window, …}bubbles: falsecancelBubble: falsecancelable: falsecomposed: falsecurrentTarget: Window {parent: Window, opener: null, top: Window, length: 0, frames: Window, …}defaultPrevented: falseeventPhase: 0isTrusted: truenewURL: "http://localhost:63342/javascript_core/BOM%E5%92%8CDOM/%E8%B7%AF%E7%94%B1/history/02%E6%96%B9%E6%B3%95/01pushState/02pushState%E4%B8%8D%E4%BC%9A%E8%A7%A6%E5%8F%91hashchange%E4%BA%8B%E4%BB%B6.html?_ijt=pkstdjn82gunkjujrusdgvfh41#abc"oldURL: "http://localhost:63342/javascript_core/BOM%E5%92%8CDOM/%E8%B7%AF%E7%94%B1/history/02%E6%96%B9%E6%B3%95/01pushState/02pushState%E4%B8%8D%E4%BC%9A%E8%A7%A6%E5%8F%91hashchange%E4%BA%8B%E4%BB%B6.html?_ijt=pkstdjn82gunkjujrusdgvfh41"path: [Window]returnValue: truesrcElement: Window {parent: Window, opener: null, top: Window, length: 0, frames: Window, …}target: Window {parent: Window, opener: null, top: Window, length: 0, frames: Window, …}timeStamp: 13232.86999999982type: "hashchange"__proto__: HashChangeEvent

history
History {length: 2, scrollRestoration: "auto", state: null}

history.pushState({a:1},null,'/abc')
undefined ← ← ← 没有触发事件！！
*/


/*
另外需要注意 hash改变 也会添加历史记录(并且会触发onpopstate),
浏览器的前进、后退以及执行history.forward、history.back、和history.go 也会触发hashchange事件（如果此次改变的是hash的话）
*/
</script>
</body>
</html>
